﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class AdsInforPanel : MonoBehaviour
{
    public Text msgText;
    public Text btn1Text;
    public Text btn2Text;
    public Button button1;
    public Button button2;

    Action btn1Action;
    Action btn2Action;

    RectTransformAnimation anim;

    private void Awake()
    {
        button1.onClick.AddListener(OnClickBtn1);
        button2.onClick.AddListener(OnClickBtn2);
        anim = GetComponent<RectTransformAnimation>();
        anim.BindEndAction(1, () => { Destroy(gameObject); });
    }

    public void Init(string msg, string btn1str, string btn2str, Action action1, Action action2)
    {
        msgText.text = msg;
        btn1Text.text = btn1str;
        btn2Text.text = btn2str;
        btn1Action = action1;
        btn2Action = action2;
        anim.Play(0);
    }

    void OnClickBtn1()
    {
        btn1Action?.Invoke();
        Close();
    }

    void OnClickBtn2()
    {
        btn2Action?.Invoke();
        Close();
    }

    void Close()
    {
        anim.Play(1);
    }
}
